import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import p001 from './p001';
import p002 from './p002';
import p003 from './p003';
interface Iparam extends Event {
	page_no: number;
}
export default async function a003(fd: IFeidaoAiBrowserComponent, e: Iparam) {

	const hidden_source = fd.data.node.querySelector<HTMLInputElement>('[data-zzs="hidden_source"]').value;
	const hidden_name = fd.data.node.querySelector<HTMLInputElement>('[data-zzs="hidden_name"]').value;

	let page_no = 1;
	if (e.page_no > 0) {
		page_no = e.page_no;
	}
	const res = await nodejs<{ rs: Array<{}>, c: number }>('device-management/zj-000002/s001', {
		filter: {
			hidden_source,
			hidden_name,
			page_no
		}
	});
	if (res.rs) {
		const a = fd.data.node.querySelector<HTMLDivElement>('[data-zzs="bt2"]');
		set_node_cls(a, 'display-n', true);
		render(fd, res.rs, p001, 'p001', 'inner');
		render(fd, { pageno: page_no, total: res.c }, p002, 'p002', 'inner');
	} else {
		const b = fd.data.node.querySelector<HTMLDivElement>('[data-zzs="bt"]');
		set_node_cls(b, 'display-n', true);
		const c = fd.data.node.querySelector<HTMLDivElement>('[data-zzs="fy"]');
		set_node_cls(c, 'display-n', true);
		render(fd, '', p003, 'p003', 'inner');
	}

}
